Skip to content

feat: Add Pubky Ring auth callbacks#917

Merged
ovitrif merged 5 commits intomasterfrom
codex-pubky-ring-callbacks-913
May 6, 2026
Merged

feat: Add Pubky Ring auth callbacks#917
ovitrif merged 5 commits intomasterfrom
codex-pubky-ring-callbacks-913

Conversation

@ben-kaufman
Copy link
Copy Markdown
Contributor

Description

Fixes #913.

  • Add Pubky Ring x-success, x-cancel, x-error, and x-source=Bitkit callback parameters before launching Ring auth.
  • Handle bitkit://pubky-auth/success, bitkit://pubky-auth/cancel, and bitkit://pubky-auth/error deeplinks in the app.
  • Keep relay-based completePubkyAuth() as the source of truth for successful session completion.
  • Reset pending Ring auth UI on cancel/error callbacks and show the Ring error message when present.
  • Add focused tests for callback URL generation and callback parsing.
  • Clean existing import-order detekt findings so ./gradlew detekt reports no issues.

Preview

N/A, deeplink/auth flow change.

QA Notes

Validation run:

  • git diff --check passed
  • ./gradlew detekt passed with no findings
  • ./gradlew compileDevDebugKotlin attempted, but blocked at :app:checkDevDebugAarMetadata because GitHub Packages credentials are missing (Username must not be null) for private Maven artifacts
  • ./gradlew testDevDebugUnitTest attempted, but blocked for the same GitHub Packages credential issue

Suggested manual QA:

  • Start Pubky Ring auth from Bitkit and approve in Ring; Bitkit should be reopened and continue the existing relay completion/import flow.
  • Cancel in Ring; Bitkit should be reopened and the waiting/loading state should clear.
  • Trigger a Ring error callback; Bitkit should be reopened, clear the pending auth state, and show an error toast.

@ben-kaufman ben-kaufman force-pushed the codex-pubky-ring-callbacks-913 branch from 946e7f2 to 6d6c98f Compare April 28, 2026 15:23
@ben-kaufman ben-kaufman marked this pull request as ready for review April 28, 2026 15:24
Comment thread app/src/main/java/to/bitkit/models/PubkyRingAuthCallback.kt
@ben-kaufman ben-kaufman force-pushed the codex-pubky-ring-callbacks-913 branch 2 times, most recently from fc79786 to 66e7592 Compare April 28, 2026 15:45
Comment thread app/src/main/java/to/bitkit/models/PubkyRingAuthCallback.kt
@claude

This comment has been minimized.

@piotr-iohk
Copy link
Copy Markdown
Collaborator

Not sure if it is Bitkit or Ring, but going back to ring from Bitkit does not open the auth window correctly.
To reproduce:

  • Import with Pubky Ring from Bitkit
  • tap "Deny" in pubky-ring
  • Import with Pubky Ring from Bitkit again
  • see the Auth window does not appear (seems to be suppressed)

Below comparison with iOS (left), where the issue is not appearing:

Screen.Recording.2026-04-29.at.11.02.47.mov

@piotr-iohk
Copy link
Copy Markdown
Collaborator

Also see that x-error message in tooltip is presented for very short time. Could be presented a bit longer I think.

Screen.Recording.2026-04-30.at.14.29.39.mov

@ben-kaufman ben-kaufman force-pushed the codex-pubky-ring-callbacks-913 branch 2 times, most recently from 787db77 to 38553ad Compare April 30, 2026 18:18
@ovitrif ovitrif added this to the 2.3.0 milestone May 5, 2026
@ovitrif ovitrif force-pushed the codex-pubky-ring-callbacks-913 branch from 38553ad to c0de815 Compare May 5, 2026 17:02
@ovitrif
Copy link
Copy Markdown
Collaborator

ovitrif commented May 5, 2026

Why isn't it redirecting me back from Ring? 🤔

Am I missing something?

I added new Staging Pubky, because I thought that might be the issue, that I was using Prod identity from Ring, but then again, iOS counterpart PR worked that way too (synonymdev/bitkit-ios#537), and it still doesn't work anyways with staging.

PS. Asked Codex too.
PPS. Force-push was after rebase on master + drop change in CHANGELOG.md and replace it with manually adding similar changelog entry via changelog.d/next/917.added. No code Kotlin changes.

EDIT: NVM, I figured out the issue, I had to use new Pubky Ring build, thanks @coreyphillips 🙏🏻

@ovitrif ovitrif self-requested a review May 5, 2026 17:06
Copy link
Copy Markdown
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Tested:

  • Approve
  • Deny (cancel)
  • Error (via temp patch in PubkyChoiceViewModel.startRingAuth() to send malformed pubkyauth URL to Ring.

Comment thread app/src/main/java/to/bitkit/models/PubkyRingAuthCallback.kt
Copy link
Copy Markdown
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I did figure out with Codex that it doesn't match iOS here:

Android’s invalid nonce cancel/error handling does not match iOS. iOS ignores stale/mismatched callbacks; Android currently ends the active auth attempt for invalid cancel/error.

Probably misses your latest updates to the iOS counterpart PR that got merged?

@ovitrif
Copy link
Copy Markdown
Collaborator

ovitrif commented May 5, 2026

Pushed fix: ignore stale pubky callbacks (b805610)

What changed:

  • Android now matches iOS nonce validation for Pubky Ring callbacks.
  • Success/cancel/error callbacks are only trusted when the callback nonce matches the active auth attempt.
  • Missing, blank, or mismatched nonce callbacks are ignored, so stale Ring responses cannot abort a newer auth attempt.
  • Android also normalizes a bare ?nonce callback param to missing, which keeps behavior aligned with iOS and fixes the unit-test failure.

Important for testing:

  • To test approve/deny/error returning from Ring, use a Pubky Ring build from the latest nonce-fix branch/PR that preserves the callback nonce.
  • Older/current Ring builds may return something like bitkit://pubky-auth/cancel?nonce on Deny. That is intentionally ignored by Bitkit now, so Bitkit will remain waiting in that case.

Suggested manual test:

  1. Install the Android PR build.
  2. Install a Pubky Ring build that includes the nonce preservation fix.
  3. Start Pubky Ring auth from Bitkit.
  4. Approve in Ring: Bitkit should return and complete auth.
  5. Start auth again and Deny in Ring: Bitkit should return and clear the waiting state.
  6. Start auth again and trigger an Error callback from Ring: Bitkit should return and show the trusted Ring error.

Stale callback check:

  • While Bitkit is waiting on a real auth attempt, open bitkit://pubky-auth/cancel?nonce=invalid via adb.
adb shell am start -a android.intent.action.VIEW -d 'bitkit://pubky-auth/cancel?nonce=invalid' to.bitkit.dev
  • Expected: Bitkit may foreground, but it should ignore the callback and keep the active auth attempt alive.

ovitrif
ovitrif previously approved these changes May 5, 2026
Copy link
Copy Markdown
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will retest test later if I get a build from Corey, to validate against the latest changes for the nodes in Pubky Ring.

Otherwise, everything is already tested and looking good, so normally this pull request can be merged.

Comment thread app/src/main/java/to/bitkit/models/PubkyRingAuthCallback.kt
@claude

This comment has been minimized.

# Conflicts:
#	app/src/main/java/to/bitkit/repositories/PubkyRepo.kt
#	app/src/test/java/to/bitkit/repositories/PubkyRepoTest.kt
@ovitrif ovitrif changed the title [codex] Add Pubky Ring auth callbacks feat: Add Pubky Ring auth callbacks May 6, 2026
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 6, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Copy link
Copy Markdown
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, retested.

@ovitrif ovitrif merged commit 6b1d680 into master May 6, 2026
16 of 18 checks passed
@ovitrif ovitrif deleted the codex-pubky-ring-callbacks-913 branch May 6, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return to Bitkit after Pubky Ring auth

3 participants